import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


// 解决重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router =  new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: () => import('@/views/index'),
      redirect: '/home',
      children: [
        {path: 'home', component: () => import('@/views/home/index')},
        {path: "movie/detail/:id(\\d+)", component: () => import('@/views/movie/detail')},
        {path: "search", component: () => import('@/views/search/index')},
        {path: "category", component: () => import('@/views/category/index')},
        {path: "share", component: () => import('@/views/share/index')},
        {path: "demand", component: () => import('@/views/demand/index')},
        {path: "theme", component: () => import('@/views/theme/index')},
        {path: "collection", component: () => import('@/views/collection/index')},
        {path: "themeMovie/:id(\\d+)", component: () => import('@/views/themeMovie/index')},
      ]
    },
    // {
    //   path: '/search',
    //   component: () => import('@/views/search/index'),
    //   hidden: true
    // },
  ]
})

// router.beforeEach(async (to, from, next) => {
  // console.log("2222222222222222")
  // if (store.state.username) {
  //   console.log("信息没有丢失");
  //   //信息没有丢失
  //   // 若vuex中存在用户的昵称，则说明当前有登录态
  //   next();
  // } else {
  //   console.log("信息丢失了")
  //   // 通过检测接口检验用户的登录态，
  //   // 然后将获取到的信息再次存储到vuex中
  //   //要异步改变store里的值就必须这样
  //   await store.dispatch('getUserInfo')
  //     console.log("获取信息成功");
  //     next();
  // }

// })

export default router
